package com.example.baseexercises.Redis;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author: 辛之所想
 * @create: 2025-11-15 20:42
 * @description:
 **/

@RestController
@RequestMapping("/redisString")
@Tag(name = "RedisString",description = "RedisString操作")
public class RedisString {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @GetMapping("/redisStringTest")
    @Operation(summary = "RedisString测试")
    public String redisStringTest() {
        set("redisString", "redisString", 10, TimeUnit.SECONDS);
        String result = get("redisString");
        return result;
    }

    public void set(String key, String value, long timeout, TimeUnit timeUnit) {
        stringRedisTemplate.opsForValue().set(key, value, timeout, timeUnit);
    }

    public String get(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

}
